﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<!-- example Dino Esposito -->

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Form filling (ASP.NET)</title>
</head>

<script type="text/javascript">
    function CheckMembership(source, arguments) {
        arguments.IsValid = false;
        var buf = arguments.Value;
        if (buf == "Normal" || buf == "Silver" ||
            buf == "Gold" || buf == "Platinum")
            arguments.IsValid = true;
    }
</script>


<body>
    <div id="pageAbstract">
        <p>
            Using validation controls to fill a form. No AJAX features are used in this demo.
        </p>
    </div>
    <div id="pageContent">
        <h2>ASP.NET validators in action</h2>
        <form id="form1" runat="server">
   	        <h3>Fill the form out</h3>  

	        <table>
	            <tr>
	                <td>Name</td><td>*</td>
		            <td><asp:textbox runat="server" id="fname" />
		                <asp:RequiredFieldValidator runat="server" id="fnameValidator" 
		                    ControlToValidate="fname" 
			                Text="!!!"
		                    ErrorMessage="Name is mandatory" /></td></tr>
	            <tr>
	                <td>Last Name</td><td>*</td>
		            <td><asp:textbox runat="server" id="lname" />
		                <asp:RequiredFieldValidator runat="server" id="lnameValidator" 
		                    ControlToValidate="lname" 
			                Text="!!!"
		                    ErrorMessage="Last name is mandatory" /></td></tr>
	            <tr>
	                <td>Age</td><td></td>
		            <td><asp:textbox runat="server" id="age" />
		                <asp:CompareValidator runat="server" id="ageValidator" 
		                    ControlToValidate="age" 
			                Operator="GreaterThanEqual" 
			                ValueToCompare="18"
		                    Type="integer"
		                    ErrorMessage="Age must be at least 18." /></td></tr>
	            <tr>
	                <td>Email</td><td></td>
		            <td><asp:textbox runat="server" id="email" />
		                <asp:RegularExpressionValidator runat="server" id="emailValidator" 
		                    ControlToValidate="email" 
			                ValidationExpression="[a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+" 
		                    ErrorMessage="Must be an email address." /></td></tr>
	            <tr>
	                <td>Hire Date</td><td></td>
		            <td><asp:textbox runat="server" id="hired" />
		                <asp:CompareValidator runat="server" id="hiredValidator" 
		                    ControlToValidate="hired" 
			                Display="Static"  
			                Operator="DataTypeCheck" 
		                    Type="date"
		                    ErrorMessage="Must enter a date." />
		                <asp:RangeValidator runat="server" id="hiredDateValidator" 
		                    ControlToValidate="hired" 
			                Display="Dynamic"
		                    MinimumValue="1999-1-1"
			                MaximumValue="9999-12-31"
		                    Type="Date"
		                    ErrorMessage="Date after 1-1-99." /></td></tr>
	            <tr>
	                <td>Membership Level</td><td></td>
		            <td><asp:textbox runat="server" id="membership" />
		                <asp:CustomValidator runat="server" id="membershipValidator" 
		                     ControlToValidate="membership" 
			                 ClientValidationFunction="CheckMembership"
		                     ErrorMessage="Must be Gold or Platinum." /></td></tr>
	        </table>
        	
	        <asp:linkbutton ID="Linkbutton1" runat="server" Text="Add..." />
            <hr>
            <asp:ValidationSummary ID="ValidationSummary1" runat="server"  
		        ShowMessageBox="true" 
		        ShowSummary="true" 
		        HeaderText="The following errors occurred:"
		        DisplayMode="BulletList" />
        </form>
    </div>
</body>
</html>
